# -*- coding: UTF-8 -*-
import re
import hashlib
import time

def weather_switch(condition, sunRise, sunSet):
    condition = condition.encode('utf-8')
    dateline = time.time()
    if sunRise != '':
        sunRise_line = time.mktime(time.strptime(sunRise,'%Y-%m-%d %H:%M:%S'))
        sunSet_line = time.mktime(time.strptime(sunSet,'%Y-%m-%d %H:%M:%S'))
        if dateline >= sunRise_line and dateline <= sunSet_line:
            day = True #白天
        else:
            day = False #晚上
    else:
        day = True
    if condition == '晴' and day == True:
        return 'CLEAR_DAY'
    if condition == '晴' and day == False:
        return 'CLEAR_NIGHT'
    if re.search('云', condition) != None and day == True:
        return 'PARTLY_CLOUDY_DAY'
    if re.search('云', condition) != None and day == False:
        return 'PARTLY_CLOUDY_NIGHT'
    elif condition == '阴':
        return 'CLOUDY'
    elif condition == '冻雨':
        return 'SLEET'
    elif re.search('雪', condition) != None:
        return 'SNOW'
    elif re.search('雨', condition) != None:
        return 'RAIN'
    elif condition == '霾':
        return 'HAZE'
    elif re.search('雾', condition) != None:
        return 'FOG'
    elif re.search('风', condition) != None:
        return 'WIND'
    else:
        return 'CLOUDY' #未知天气默认阴天
def hash_md5(md5_str):
    m = hashlib.md5()
    m.update(md5_str)
    return m.hexdigest()


